package com.yf.controller.admin.course;

import java.util.List;
import java.util.Map;

import com.yf.entity.course.LessonOrderEntity;
import com.yf.service.course.LessonOrderService;
import com.yf.vo.OrderBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 订单Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 31 09:51:27 CST 2018
 */
@RestController
@RequestMapping("/lessonorder")
public class LessonOrderController {
    @Autowired
    private LessonOrderService lessonOrderService;

    /**
     * 列表订单
     */
    @RequestMapping("/list")
    @RequiresPermissions("lessonorder:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<LessonOrderEntity> lessonOrderList = lessonOrderService.queryList(params);
        return R.ok(new PageInfo(lessonOrderList));
    }

    /**
     * 查看订单
     */
    @SysLog("查看订单")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lessonorder:info")
    public R info(@PathVariable("id") Long id) {
        LessonOrderEntity lessonOrder = lessonOrderService.get(id);

        return R.ok(lessonOrder);
    }

    /**
     * 保存订单
     */
    @SysLog("保存订单")
    @RequestMapping("/save")
    @RequiresPermissions("lessonorder:save")
    public R save(LessonOrderEntity lessonOrder) {
        lessonOrderService.save(lessonOrder);

        return R.ok(lessonOrder);
    }

    /**
     * 修改订单
     */
    @SysLog("修改订单")
    @RequestMapping("/update")
    @RequiresPermissions("lessonorder:update")
    public R update(LessonOrderEntity lessonOrder) {
        lessonOrderService.update(lessonOrder);

        return R.ok(lessonOrder);
    }

    /**
     * 删除订单
     */
    @SysLog("删除订单")
    @RequestMapping("/delete")
    @RequiresPermissions("lessonorder:delete")
    public R delete(@RequestBody Long[]ids) {
        lessonOrderService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有订单
     */
    @SysLog("所有订单")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<LessonOrderEntity> lessonOrderList = lessonOrderService.queryList(params);

        return R.ok(lessonOrderList);
    }

    /***********自定义开始***********/

    /**
     * back 订单信息
     * @return
     */
    @RequestMapping("/orderList")
    public R getCampaignVoList(@RequestParam Map<String, Object> params){
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<OrderBackVo> list = lessonOrderService.orderList(params);
        return R.ok(new PageInfo(list));
    }

}
